#include "colors.h"

using namespace std;

Colors::Colors()
{

    //Creation of the main grid
    layoutColors = new QGridLayout(this);


    //Creation of the window containing the Colorview
    viewColor = new ColorView();
    viewColor->setUpdatesEnabled(true);

    //Creation of the window containing the gridlayoutRGB
    widgetRGB = new QWidget(this);
    //Creation of the main gridlayout contained in the widgetRGB
    layoutRGB = new QGridLayout(widgetRGB);
    //Creation of the all labels in this layoutRGB
    labelTitreRGB = new QLabel();
    labelR = new QLabel();
    labelG = new QLabel();
    labelB = new QLabel();
    labelCodeR = new QLabel();
    labelCodeG = new QLabel();
    labelCodeB = new QLabel();

    //Creation of the window containing the gridlayoutYUV
    widgetYUV = new QWidget();
    //Creation of the main gridlayout contained in the widgeYUV
    layoutYUV = new QGridLayout(widgetYUV);
   //Creation of the all labels in this layoutYUV
    labelTitreYUV = new QLabel();
    labelY = new QLabel();
    labelU = new QLabel();
    labelV = new QLabel();
    labelCodeY = new QLabel();
    labelCodeU = new QLabel();
    labelCodeV = new QLabel();


    // disposition of all objects
    layoutColors->addWidget(viewColor, 0, 0, 1, 1, Qt::AlignTop);
    layoutColors->addWidget(widgetRGB, 0, 1, 1, 1, Qt::AlignTop);
    layoutColors->addWidget(widgetYUV, 1, 1, 1, 1, Qt::AlignTop);


    layoutRGB->addWidget(labelTitreRGB,0,0,1,2,Qt::AlignTop | Qt::AlignHCenter);
    layoutRGB->addWidget(labelR,1,0,1,1,Qt::AlignTop | Qt::AlignHCenter);
    layoutRGB->addWidget(labelG,2,0,1,1,Qt::AlignTop | Qt::AlignHCenter);
    layoutRGB->addWidget(labelB,3,0,1,1,Qt::AlignTop | Qt::AlignHCenter);
    layoutRGB->addWidget(labelCodeR,1,1,1,1,Qt::AlignTop);
    layoutRGB->addWidget(labelCodeG,2,1,1,1,Qt::AlignTop);
    layoutRGB->addWidget(labelCodeB,3,1,1,1,Qt::AlignTop);

    layoutYUV->addWidget(labelTitreYUV,0,0,1,2,Qt::AlignTop | Qt::AlignHCenter);
    layoutYUV->addWidget(labelY,1,0,1,1,Qt::AlignTop | Qt::AlignHCenter);
    layoutYUV->addWidget(labelU,2,0,1,1,Qt::AlignTop | Qt::AlignHCenter);
    layoutYUV->addWidget(labelV,3,0,1,1,Qt::AlignTop | Qt::AlignHCenter);
    layoutYUV->addWidget(labelCodeY,1,1,1,1,Qt::AlignTop);
    layoutYUV->addWidget(labelCodeU,2,1,1,1,Qt::AlignTop);
    layoutYUV->addWidget(labelCodeV,3,1,1,1,Qt::AlignTop);


    labelTitreRGB->setText(QString::fromUtf8("RGB"));
    labelR->setText(QString::fromUtf8("R"));
    labelR->setFixedSize(20,15);
    labelR->setStyleSheet("background-color: rgba(255, 0, 0, 85)");
    labelR->setAlignment(Qt::AlignCenter);
    labelG->setText(QString::fromUtf8("G"));
    labelG->setFixedSize(20,15);
    labelG->setStyleSheet("background-color: rgba(0, 255, 0, 85)");
    labelG->setAlignment(Qt::AlignCenter);
    labelB->setText(QString::fromUtf8("B"));
    labelB->setFixedSize(20,15);
    labelB->setStyleSheet("background-color: rgba(0, 0, 255, 85)");
    labelB->setAlignment(Qt::AlignCenter);


    labelTitreYUV->setText(QString::fromUtf8("YUV"));
    labelY->setText(QString::fromUtf8("Y"));
    labelY->setFixedSize(20,15);
    labelY->setStyleSheet("background-color: rgba(0, 0, 0, 85)");
    labelY->setAlignment(Qt::AlignCenter);
    labelU->setText(QString::fromUtf8("U"));
    labelU->setFixedSize(20,15);
    labelU->setStyleSheet("background-color: rgba(100, 0, 0, 85)");
    labelU->setAlignment(Qt::AlignCenter);
    labelV->setText(QString::fromUtf8("V"));
    labelV->setFixedSize(20,15);
    labelV->setStyleSheet("background-color: rgba(0, 0, 100, 85)");
    labelV->setAlignment(Qt::AlignCenter);

    this->setLayout(layoutColors);

    viewColor->setForegroundColor(QColor(0,0,0,255));
    viewColor->setBackgroundColor(QColor(255,255,255,255));

    modifLabel(0, 0, 0, 0, 0, 0, 255);
}

void Colors::modifLabel(int red, int green, int blue, int y , int u, int v, int alpha){
    if(alpha == 0)
    {
        labelCodeR->setText("");
        labelCodeG->setText("");
        labelCodeB->setText("");
        labelCodeY->setText("");
        labelCodeU->setText("");
        labelCodeV->setText("");
        viewColor->setForegroundColor(QColor(red,green,blue,alpha));
    }else{

        QString str;

        labelCodeR->setText(str.setNum(red));
        labelCodeG->setText(str.setNum(green));
        labelCodeB->setText(str.setNum(blue));
        labelCodeY->setText(str.setNum(y));
        labelCodeU->setText(str.setNum(u));
        labelCodeV->setText(str.setNum(v));
        viewColor->setForegroundColor(QColor(red,green,blue,255));
    }


}
